package com.zzptc.zzsgz.bdsjws.receiver;

import android.app.FragmentManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.fragments.UpdataVersionDialogFragment;
import com.zzptc.zzsgz.bdsjws.services.IVersionUpData;
import com.zzptc.zzsgz.bdsjws.utils.CheckUpdataVersion;
import com.zzptc.zzsgz.bdsjws.vo.VersionInfo;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CheckUpdateBroadcase extends BroadcastReceiver {
    public CheckUpdateBroadcase() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
//        // TODO: This method is called when the BroadcastReceiver is receiving
//        // an Intent broadcast.
//        throw new UnsupportedOperationException("Not yet implemented");
        if(CheckUpdataVersion.getCheckDateUtil()){
                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl("http://119.29.227.211/")
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();
                IVersionUpData service = retrofit.create(IVersionUpData.class);
                Call<VersionInfo> call = service.getVersionInfo();
                call.enqueue(new Callback<VersionInfo>() {
                    @Override
                    public void onResponse(Call<VersionInfo> call, Response<VersionInfo> response) {
                        //网络正常   可以下载~~~已经是最新版本
                        VersionInfo versionInfo =  response.body();
                        int netcode = versionInfo.getVersionCode();
                        int oldcode = CheckUpdataVersion.getVersionCode(MyApplication.getContext());
                        if (netcode > oldcode) {

                        }
                    }
                    @Override
                    public void onFailure(Call<VersionInfo> call, Throwable t) {
                        //网络比较慢

                    }
                });
        }
    }

    public boolean getCheckDate(){


        return false;
    }
}
